//压缩字符串(一)
import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param param string字符串 
     * @return string字符串
     */
    public String compressString (String param) {
        // write code here
        StringBuilder ret = new StringBuilder();
        char[] arr = param.toCharArray();
        int count = 1;
        for (int i = 0; i < arr.length; i++) {

            if (i != 0 && arr[i] == arr[i-1]) {
                count++;
            } else {
                if (count != 1) {
                    ret.append(count);
                }
                ret.append(arr[i]);
                count = 1;
            }
        }
        if (count != 1) {
            ret.append(count);
        }
        return ret.toString();
    }
}
//十字爆破
import java.util.*;
import java.io.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static void main(String[] args) throws IOException {
        Read in = new Read();
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();
        int m = in.nextInt();
        long[] sumRow = new long[n];
        long[] sumlen = new long[m];
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                long tmp = in.nextInt();
                arr[i][j] = tmp;
                sumlen[j] += tmp;
                sumRow[i] += tmp;
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                out.print(sumlen[j]+sumRow[i]-arr[i][j]);
                if (j != m-1) {
                    out.print(" ");
                }
            }
            out.println();
        }        
        out.close();
    }
}
class Read{
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public String next() throws IOException{
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
}
class Solution {
    public int missingNumber(int[] nums) {
        int n = nums.length;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += nums[i];
        }
        return (n * (n+1) / 2) - sum;
    }
}
class Solution {
    public void rotate(int[] nums, int k) {
        k %= nums.length;
        remove(nums, 0, nums.length - 1);
        remove(nums, 0, k - 1);
        remove(nums, k, nums.length - 1);

    }

    public void remove(int[] nums, int l, int r) {
        while(l < r) {
            int tmp = nums[l];
            nums[l] = nums[r];
            nums[r] = tmp;
            l++;
            r--;
        }
    }
}